package com.api.apiinterface.controller;

import cn.hutool.core.util.RandomUtil;
import com.api.apiinterface.model.Word;
import com.api.apiinterface.service.WordService;
import com.api.clientsdk.model.User;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/word")
public class WordController {

    @Resource
    private WordService wordService;

    @GetMapping("/words")
    public String getWordsByGet(){
        // 获取数据库中 土味情话 的数量
        long count = wordService.count();
        long wordId = RandomUtils.nextLong(0,count);
        QueryWrapper<Word> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",wordId);
        List<Word> list = wordService.list(queryWrapper);
        if (list.equals(null)) return "";
        //只有一条数据
        return list.get(0).getWords();
    }
}
